= kujaku do |k|
  - k.text
  - k.helper :journal_period_crit
  - k.multi_choice :repayment_period, resource_model.repayment_period.values.map{ |s| [s.tl, s] }, label: :repayment_period.tl
  - cash_ids = Loan.all.pluck(:cash_id).compact.uniq
  - cashes = Cash.where(id: cash_ids).reorder(:name)
  - if cashes.any?
    - k.helper do
      %label= Cash.human_attribute_name(:name)
      = select_tag(:cash_id, options_for_select([[]] +  cashes.map{|u| [u.name, u.id]}, params[:cash_id].to_i))

- main_toolbar do |t|
  = t.new params: { redirect: nil }
  = t.export :loan_registry, key: Time.zone.now.to_s, resource: @loans

  %span.btn-group.action-form.hidden
    - bookkeep_until = params[:until].to_s =~ /\A\d\d\d\d\-\d\d\-\d\d\z/ ? params[:until].to_date : (Time.zone.today - 1.month).end_of_month
    = link_to :accounting.tl, { action: :bookkeep, until: bookkeep_until.iso8601, redirect: request.fullpath }, { class: 'btn btn-default', name: 'loan_ids', data: { confirm: :are_you_sure.tl, update_link_with: '#bookkeep-loans-until', complete_link_with_checked_row_ids: '#loans-list input[type="checkbox"]', show_if_checked: 'any' }, method: :post }
    %span.add-on= :up_to.tl.downcase
    = date_field_tag(:until, bookkeep_until, id: 'bookkeep-loans-until', data: { max_date: Time.zone.today.iso8601 })

= main_list
